﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;


namespace IsolatedStorage
{
    public partial class MainPage : PhoneApplicationPage
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            var appStorage = IsolatedStorageFile.GetUserStoreForApplication();
            string fileName = "simple.txt";

            using (var file=appStorage.OpenFile(fileName,System.IO.FileMode.OpenOrCreate,System.IO.FileAccess.Write))
            {
                using (var writter=new System.IO.StreamWriter(file))
                {
                   writter.Write(infoTextBox.Text);
                }
            }
        }

        private void ClearButton_Click(object sender, RoutedEventArgs e)
        {
            infoTextBox.Text = "";
        }

        private void OpenButton_Click(object sender, RoutedEventArgs e)
        {
            using (IsolatedStorageFile store=IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (System.IO.StreamReader sr=new System.IO.StreamReader(store.OpenFile("simple.txt",System.IO.FileMode.Open,System.IO.FileAccess.Read)))
                {
                    infoTextBox.Text = sr.ReadToEnd();
                }
            }
        }
    }
}
